<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>登录页面</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="css/login.css">
	<script type="text/javascript" src="<%=basePath%>/js/jquery-1.8.3.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>/js/bootstrap.min.js"></script>

  </head>
  
  <body class="jumbotron">
   	<form id="form1">
	   	<div class="login_box">
			<div class="login_title" style="letter-spacing: 2px;">用户登录</div>
			<div class="login_body">
				<div class="form-group">
					<i class="user_tb"></i>
					<span id="result"></span>
					<input id="username" class="form-control" name="username" placeholder="请输入用户账号" type="text">
				</div>
				<div class="form-group">
					<i class="pass_tb"></i>
					<input id="password" class="form-control" name="password" placeholder="请输入用户密码" type="password">
				</div>
				<div>
					<input type="button" id="sub" value="立即登录" onclick="loginTest()" class="btn btn-default" style="width: 262px;height: 39px;background-color: #0AC940;color: white;letter-spacing:5px;">
				</div>
				<br>
				<div>
		    		<a href="RegistUserTest.html" class="btn btn-default" style="width: 262px;height: 39px;background-color: #0AC940;color: white;letter-spacing:5px;">点击注册</a>
		    	</div>
			</div>
		</div>
    </form>
    
    <script type="text/javascript">
    	function loginTest() {
    		var result = document.getElementById("result");
    		document.getElementById("sub").value = "登陆中..";
    		$.ajax({
    			url : "user_login",
    			type: "post",
    			data: {
    				"username" : $("#username").val(),
    				"password" : $("#password").val()
    			},
    			success : function(data) {
					console.log(data);
	    			if (data == "登录失败") {
  						result.innerHTML = "账号或密码错误";
    					document.getElementById("sub").value = "立即登录";
    					result.style.color = "red";
	    			} else {
	    				window.location.href = "loginSuccessMain.jsp";	    
	    			}
    			},
    			error : function(data) {
    			}
    		});
    	}
    </script>
  </body>
</html>
